package com.example.lanouhn.bantangapp.activities.utils;


import com.example.lanouhn.bantangapp.activities.contants.TogSun;

import org.json.JSONArray;
import org.json.JSONObject;

import java.util.ArrayList;
import java.util.List;

/**
 * 解析Json数据
 */
public class JsonUtils_TogSun {

    /**
     * @param json json字符串
     * @return 搜索晒单列表
     */
    public static List<TogSun> getsunList(String json) {
        List<TogSun> list = new ArrayList<>();
        try {
            JSONObject jsonObject = new JSONObject(json);

            JSONArray jsonArray = jsonObject.getJSONArray("data");

            for (int i = 0; i < jsonArray.length(); i++) {
                JSONObject j = jsonArray.getJSONObject(i);


                TogSun m = new TogSun();
                m.setContent(j.getString("content"));
                m.setMiddle_pic_url(j.getString("middle_pic_url"));

                m.setDynamic(j.getJSONObject("dynamic"));
                JSONObject d = m.getDynamic();
                m.setLikes( d.getString("likes"));

                m.setUser(j.getJSONObject("user"));
                JSONObject s =  m.getUser();
               m.setNickname( s.getString("nickname"));
                m.setAvatar(s.getString("avatar"));

                list.add(m);
            }
        } catch (Exception e) {
            e.printStackTrace();
        }
        return list;
    }
}
